package com.inkyi.assistant.app.component.rsyntax.action;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ChangeSyntaxStyleAction implements ActionListener {

    private static final Map<String, String> nameMap = new HashMap<>();

    static {
//        String SYNTAX_STYLE_ASSEMBLER_X86 = "text/asm";
//        String SYNTAX_STYLE_BBCODE = "text/bbcode";
//        String SYNTAX_STYLE_CLOJURE = "text/clojure";
//        String SYNTAX_STYLE_CPLUSPLUS = "text/cpp";
//        String SYNTAX_STYLE_CSHARP = "text/cs";
//        String SYNTAX_STYLE_CSV = "text/csv";
//        String SYNTAX_STYLE_D = "text/d";
//        String SYNTAX_STYLE_DART = "text/dart";
//        String SYNTAX_STYLE_DELPHI = "text/delphi";
//        String SYNTAX_STYLE_DTD = "text/dtd";
//        String SYNTAX_STYLE_FORTRAN = "text/fortran";
//        String SYNTAX_STYLE_GROOVY = "text/groovy";
//        String SYNTAX_STYLE_HTACCESS = "text/htaccess";
//        String SYNTAX_STYLE_LISP = "text/lisp";
//        String SYNTAX_STYLE_LUA = "text/lua";
//        String SYNTAX_STYLE_MAKEFILE = "text/makefile";
//        String SYNTAX_STYLE_MXML = "text/mxml";
//        String SYNTAX_STYLE_NSIS = "text/nsis";
//        String SYNTAX_STYLE_PROPERTIES_FILE = "text/properties";
//        String SYNTAX_STYLE_RUST = "text/rust";
//        String SYNTAX_STYLE_SAS = "text/sas";
//        String SYNTAX_STYLE_SCALA = "text/scala";
//        String SYNTAX_STYLE_TCL = "text/tcl";
//        String SYNTAX_STYLE_UNIX_SHELL = "text/unix";
//        String SYNTAX_STYLE_VISUAL_BASIC = "text/vb";
//        String SYNTAX_STYLE_WINDOWS_BATCH = "text/bat";
        nameMap.put("NONE", SyntaxConstants.SYNTAX_STYLE_NONE);
        nameMap.put("6502 Assembler", SyntaxConstants.SYNTAX_STYLE_ASSEMBLER_6502);
        nameMap.put("ActionScript", SyntaxConstants.SYNTAX_STYLE_ACTIONSCRIPT);
        nameMap.put("C", SyntaxConstants.SYNTAX_STYLE_C);
        nameMap.put("CSS", SyntaxConstants.SYNTAX_STYLE_CSS);
        nameMap.put("Dockerfile", SyntaxConstants.SYNTAX_STYLE_DOCKERFILE);
        nameMap.put("Go", SyntaxConstants.SYNTAX_STYLE_GO);
        nameMap.put("Handlebars", SyntaxConstants.SYNTAX_STYLE_HANDLEBARS);
        nameMap.put("Hosts", SyntaxConstants.SYNTAX_STYLE_HOSTS);
        nameMap.put("HTML", SyntaxConstants.SYNTAX_STYLE_HTML);
        nameMap.put("INI", SyntaxConstants.SYNTAX_STYLE_INI);
        nameMap.put("Java", SyntaxConstants.SYNTAX_STYLE_JAVA);
        nameMap.put("JavaScript", SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        nameMap.put("JSP", SyntaxConstants.SYNTAX_STYLE_JSP);
        nameMap.put("JSON", SyntaxConstants.SYNTAX_STYLE_JSON_WITH_COMMENTS);
        nameMap.put("Kotlin", SyntaxConstants.SYNTAX_STYLE_KOTLIN);
        nameMap.put("LaTeX", SyntaxConstants.SYNTAX_STYLE_LATEX);
        nameMap.put("Less", SyntaxConstants.SYNTAX_STYLE_LESS);
        nameMap.put("Markdown", SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
        nameMap.put("Perl", SyntaxConstants.SYNTAX_STYLE_PERL);
        nameMap.put("PHP", SyntaxConstants.SYNTAX_STYLE_PHP);
        nameMap.put("Proto", SyntaxConstants.SYNTAX_STYLE_PROTO);
        nameMap.put("Python", SyntaxConstants.SYNTAX_STYLE_PYTHON);
        nameMap.put("Ruby", SyntaxConstants.SYNTAX_STYLE_RUBY);
        nameMap.put("Rust", "text/rust");
        nameMap.put("SQL", SyntaxConstants.SYNTAX_STYLE_SQL);
        nameMap.put("TypeScript", SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT);
        nameMap.put("XML", SyntaxConstants.SYNTAX_STYLE_XML);
        nameMap.put("YAML",SyntaxConstants.SYNTAX_STYLE_YAML);



    }


    public static List<String> getStyleKey() {
        Set<String> keySet = nameMap.keySet();
        return keySet.stream().sorted().toList();
    }

    private final RSyntaxTextArea textArea;

    public ChangeSyntaxStyleAction(RSyntaxTextArea textArea) {
        this.textArea = textArea;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JComboBox<String> source = (JComboBox<String>) e.getSource();
        String selectedItem = (String) source.getSelectedItem();
        if(nameMap.containsKey(selectedItem)){
            textArea.setSyntaxEditingStyle(nameMap.get(selectedItem));
        }
    }

}
